<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>Gestalt Sample: Tests </title>

    <script src="js/jquery.js" type="text/javascript"></script>

    <script src="js/gestalt.js" type="text/javascript"></script>

</head>
<body>

<script language="python">

# imports
from System.Windows.Shapes import * # exposes Rectangle to scope since not added by default
from System.Diagnostics import * # enables outputing to a debug window!

# localize the XAML objects, so we keep the page footprint a tad smaller
grid = me.grid
listbox = me.listbox
textbox = me.textbox
button = me.button


# define the event handler for button MouseLeftButtonDown
def button_click(a,b):
    # tuple example: tuples can be wrapped
    months = ('January', 'February', 'March', 'April','May', 'June',
    'July', 'August', 'September', 'October', 'November', 'December')
    window.Alert ("The 5th month of the year is: " + months[ 5 - 1 ]) # zero based ordinal
    
# add an eventhandler for the button MouseLeftButtonDown event
# this must occur after the event handler is define above
button.Click += button_click

# simple function example
def createRectangle():
    newRect = Rectangle()
    newRect.Fill = SolidColorBrush(Colors.Red)
    newRect.Width = 20
    newRect.Height = 20
    newRect.RadiusX = 5
    newRect.RadiusY = 5
    return newRect
    
Debug.WriteLine("Hello debug"); # write out to debug window
print "hello" # oddly doesn't fail

# simple while loop
a = 0
while a < 10: 
    a = a + 1
    grid.Width = grid.Width - 20 # reduce the size of the grid on each pass

#
# dictionary manipulation examples
#
ages = {}
ages['Hans'] = 46
ages['Roxane'] = 14
ages['Alex'] = 9
ages['Candice'] = 26

#window.Alert (ages.ToString())

if ages.has_key('Candice'):
    # the ToString() method/function converts an object such as an int to string
    textbox.Text = ages['Candice'].ToString() 
    # add it as an item to the listbox.
    listbox.Items.Add( ages['Candice'].ToString() )

keys = ages.keys()
keys.sort()
# iterative loop
for value in keys:
    listbox.Items.Add(value)

values = ages.values()
values.sort()
# iterative loop
for value in values:
    listbox.Items.Add( value.ToString() )

# simple condition
if a == 10: #conditional
    # set the background color
    grid.Background = SolidColorBrush(Colors.Green)

# add a Rectangle to the existing canvas
grid.Children.Add(createRectangle())

# KEEP!!!!!!!!!!!!!!!! This was very very hard to find, ironically. You'd think...
#import sys
#try:
#    object = XamlReader.Load(_dot)
#except:
#    Debug.WriteLine(sys.exc_info())

</script>

    <!-- This isn't a part of the sample, but a link back to the Gestalt site -->
    <div id="upsell" style="color:#fff; font-size: 13px; font-family:'Lucida Grande','Lucida Sans Unicode',Helvetica,Arial,Lucida,Verdana,sans-serif; margin-bottom: 30px;">
        <a href="http://www.visitmix.com/labs/gestalt/samples.html" style="background-color: #000; color: #fff; display: block; text-decoration: none;" onmouseover="this.style.color='#000'; this.style.background='#ccc'" onmouseout="this.style.color='#fff'; this.style.background='#000'">
		    <span style="display:block; padding: 8px; text-align:center;">&laquo; Check out other samples on the Gestalt web site</span>
	    </a>
    </div>

    <!-- If you link to a XAML file, you'll be able to view the page correctly only through a server 
         (e.g. apache or IIS) because of security sandbox reasons. To enable running the file locally 
         place the XAML inline directly inside the xml element -->
    
    <xml id="TODO" class="xaml" width="800" height="600">
        <Grid x:Name="grid" Width="800" Height="600" Background="Tan">
        
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="500"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            
        <StackPanel Orientation="Horizontal" Grid.Row="0">
            <Button x:Name="button" Content="What is the 5th Month of the Year?"></Button>
            <TextBlock x:Name="textbox"  FontFamily="Arial" Foreground="Purple" FontSize="50" Margin="20,0,0,0">Hello, World!</TextBlock>
        </StackPanel>
        
        <ListBox x:Name="listbox" Grid.Row="2"></ListBox>
		    
	    </Grid>
    </xml>
    
</body>
</html>
